<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\BankCard;
use App\Http\Controllers\Api\V1\Requests\BankCardRequest;
use App\Http\Controllers\Api\V1\Resources\BankCardResource;

class BankCardsController extends Controller
{
	public function store(BankCardRequest $request)
    {
        $bank_card = $request->user()->addBnakCard();
        return response(null, 204);
    }

    public function index()
    {
        $bankCards = request()->user()->bankCards()->where("method",'bank')->get()->toArray();
        $alipay = request()->user()->bankCards()->where("method",'alipay')->get()->toArray();
        $wxpay = request()->user()->bankCards()->where("method",'wxpay')->get()->toArray();
        
        return response()->json(['bank_cards' => $bankCards,'alipay'=>$alipay, 'wxpay'=>$wxpay]);
    }


    public function update(BankCardRequest $request)
    {
        
         $bank_card = $request->user()->updateBnakCard();

        return response(null, 204);
    }


    public function destroy(BankCard $card)
    {
        $this->authorize('own', $card);
        $card->delete();
        return response(null, 204);
    }
}
